<?php

class Default_Model_Users  extends Default_Model_Doctrine_BaseUsers
{
    const NOT_FOUND = 1;
    const WRONG_PW  = 2;
    /**
     * Perform authentication of a user
     * @param string $username
     * @param string $password
     */
    public static function authenticate($username, $password)
    {
        $user = Doctrine::getTable('Default_Model_Users')->findOneByUsername($username);

        //$user = $this->getTable()->findOneByUsername($username);
        if ($user)
        {
            if ($user->password == $password)
            return $user;

            throw new Exception(self::WRONG_PW);
        }
        throw new Exception(self::NOT_FOUND);
    }
}